<!-- 弹出框组件 -->
<template>
  <div class="toast">
    {{ message }}
  </div>
</template>

<script>
import { ref } from 'vue';
// 弹出层
export const useToast = () => {
  let timer;
  const show = ref(false);
  const toastMessage = ref('');
  const showToast = (message) => {
    // 处理点击速度过快
    clearTimeout(timer);
    toastMessage.value = message;
    show.value = true;
    timer = setTimeout(() => show.value = false, 2000)
  }
  return { show, toastMessage, showToast }
}
//composition
export default {
  props: ['message']
}
</script>

<style scoped lang="scss">
@import '@/styles/theme.scss';

.toast {
  position: fixed;
  width: 46vw;
  height: 12vw;
  line-height: 12vw;
  text-align: center;
  font-size: 14px;
  background-color: rgba(0, 0, 0, .5);
  border-radius: 5px;
  color: $white;
  left: 50%;
  top: 50%;
  margin-left: -23vw;
  margin-top: -6vw;
}
</style>